﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.ComponentModel.Composition;
using System.Windows.Input;
using System.Windows.Media;

namespace Dynamic_UI_Framework
{
    [Export(typeof(DesignerCanvas))]
    public class DesignerCanvas : Canvas
    {
        public DesignerCanvas()
        {
            this.Name = "VisualCanvas";

            this.Background = Brushes.Yellow;
           
        }
        public List<ISelectable> SelectedItems
        {
            get
            {
                if (selectedItems == null)
                    selectedItems = new List<ISelectable>();
                return selectedItems;
            }
        }
        private List<ISelectable> selectedItems;
       
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Source == this)
            {
                foreach (var item in this.Children)
                {
                    ISelectable s = item as ISelectable;
                    if (s != null)
                        s.IsSelected = false;
                }
                //foreach (ISelectable item in SelectedItems)
                //    item.IsSelected = false;
                //selectedItems.Clear();

                e.Handled = true;
            }
        }
    }

    public interface ISelectable
    {
        bool IsSelected { get; set; }
    }

}
